{{template "admin/header.html"}}
  <title>{{T "Component"}} - MINRAG</title>
{{template "admin/bodystart.html"}}

    <form id="listForm" action="{{basePath}}admin/{{.UrlPathParam}}/list" method="GET">

        <div class="layui-input-group">
            <input type="text" id="q" name="q" placeholder='{{T "Search"}}' class="layui-input">
            <div class="layui-input-split layui-input-suffix" style="cursor: pointer;">
                <i class="layui-icon layui-icon-search" onclick=""></i>
            </div>
            <div class="layui-col-md1">
                &nbsp;&nbsp;&nbsp;&nbsp;
            </div>
            <div class="layui-input-block">
                <a href="{{basePath}}admin/{{.UrlPathParam}}/save" class="layui-btn layui-bg-blue">+{{T "Add Component"}}</a>
            </div>
        </div>
    </form>
    <table class="layui-table table-component" id="table_list" lay-filter="parse-table-list">
        <thead>
            <tr>
                <th width="20%">ID</th>
                <th width="20%">{{T "Component Type"}}</th>
                <th width="10%">{{T "Sort"}}</th>
                <th width="10%">{{T "Status"}}</th>
                <th width="10%">{{T "Actions"}}</th>
            </tr>
        </thead>
        <tbody>
            <!-- 循环所有的数据 -->
            {{ range $i,$v := .Data }}
            <tr>
                <!-- 获取每一列的值 -->
                <td title="{{ .Id }}"><a href="{{basePath}}admin/{{$.UrlPathParam}}/update?id={{.Id}}" style="cursor: pointer;"> {{ .Id }} </a></td>
                <td title="{{ .ComponentType }}"> {{ .ComponentType }}</td>
                <td> {{ .SortNo }}</td>
                <td>
                    {{if eq .Status 0 }}
                    {{T "Disable"}}
                    {{else if eq .Status 1 }}
                    {{T "Active"}}
                    {{else}}
                    {{T "Unknown"}}
                    {{end}}
                </td>
                <td>
                    <button type="button" class="layui-btn layui-btn-primary layui-btn-xs" title='{{T "Edit"}}'>
                        <a href="{{basePath}}admin/{{$.UrlPathParam}}/update?id={{.Id}}">
                            <i class="layui-icon layui-icon-edit"></i>
                        </a>
                    </button>
                    <button type="button" class="layui-btn layui-btn-primary layui-btn-xs"
                        onclick="deleteFunc('{{$v.Id}}','{{basePath}}admin/{{$.UrlPathParam}}/delete');" title='{{T "Delete"}}'>
                        <i class="layui-icon layui-icon-delete"></i>
                    </button>
                </td>
            </tr>
            {{end }}
        </tbody>
    </table>
    

{{template "admin/bodyend.html"}}



<script>
    var layer;
    var $;
	layui.use(function () {
		//var table = layui.table;
		layer = layui.layer;
        $ = layui.jquery;
		
    })

    
	function deleteFunc(id, url) {
		layer.confirm('{{T "Confirm deletion?"}}', {
			icon: 3,
			title: '{{T "Confirm"}}',
			btn: ['{{T "Confirm"}}', '{{T "Cancel"}}'] //按钮
		}, function () {
			$.ajax({
				type: 'post',
				url: url,
				data: { "id": id },
				success: function (res) {
					if (res.statusCode === 1) {
						layer.msg('{{T "Delete successful"}}', function () {
							location.reload();
						});
					}else{
						var message='{{T "Delete failed!"}}';
						if(!!res.message){
							message=message+res.message
						}
						layer.msg(message);
					}
				}
			});
		});
	}

</script>